<template>
  <div>
<el-button @click="downloadTemplate()" size="small" type="primary">导入模板下载</el-button>
    <div style="margin-top:20px;"></div>
    <UploadFile
    action-url="/api/basedata/vehicleProduct/importUseModel"
    :initial-value="file"
    @change="successHandler"
    :fileTypes="['xlsx','xls']"
  >上传附件</UploadFile>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
    </div>
    <!--<importFile title="导入" actionUrl="/api/cmscloud.channel/message/dealerAttach/dealerInfo/importDealers"-->
                <!--@close="successHandler" />-->
  </div>
</template>
<script>
import moment from 'moment'
import {downloadUrl,exportExcelFile} from '@/utils'
import {downloadOptionModel} from '@/api/omFinance';
export default {
  data(){
    return{
      // urls:`${SERVER.CMSCLOUD_CHANNEL}/message/dealerAttach/dealerInfo/byAllInfo`,
      fetchParams:{

      },
      file:[],
      result:[],
      importStatus:false,
      fetchApi:()=>{},
    }
  },
  methods:{
    downloadTemplate() {
      this.$confirm('此操作将下载excel模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        downloadOptionModel().then(res => {
          console.log('适用车型导入模板',res);
          exportExcelFile(res.data, '适用车型导入模板');
        });
      });
    },
    successHandler(val){
      console.log("适用车型返回data",val)
      this.result=val[0].url?val[0].url:val.url
      if(this.result.errorList&& this.result.errorList.length>0){
        this.importFail();
      }else {
        if(this.result.successList && this.result.successList.length>0){
          this.$message({
            type: 'success',
            message: '导入成功'
          });
          this.importStatus=true;
        }else {
          this.importFail();
        }
      }
    },
    importFail(){
      this.$confirm('导入失败，有车型代码错误或禁用', '提示', {
        showCancelButton:false,
        confirmButtonText: '确定',
        type: 'warning'
      }).then(()=>{
        this.file=[];
      })
      this.importStatus=false;
    },
    closeDrawer(type){
      if(type==1){
        if(this.importStatus){
          this.$emit('close',this.result.successList)
        }else {
          this.$emit('close')
        }
      }else{
        this.$emit('close',this.file)
      }

    },
  },
}

</script>
